cd "~/replication code/"

*** Table 1
use "./data/anes9297_subset.dta", clear

egen nmis_m1 = rmiss2(rr92_scaled rr94_scaled pid92_7scaled pid94_7scaled)
nlsur (rr94_scaled ={b0}+{b1}*pid92_7scaled +{b2}*rr92_scaled) (pid94_7scaled ={a0}+{a1}*pid92_7scaled + {a2}*rr92_scaled) if white_int92 == white_int94 & nmis_m1 == 0 [aweight = V940005], r
nlsur (rr94_scaled ={b0}+({b3}+{a2})*pid92_7scaled +{b2}*rr92_scaled) (pid94_7scaled ={a0}+{a1}*pid92_7scaled + {a2}*rr92_scaled) if white_int92 == white_int94 & nmis_m1 == 0 [aweight = V940005], r 

egen nmis_m2 = rmiss2(ftdif_wb92_sc ftdif_wb94_sc pid92_7scaled pid94_7scaled)
nlsur (ftdif_wb94_sc ={b0}+{b1}*pid92_7scaled +{b2}*ftdif_wb92_sc) (pid94_7scaled ={a0}+{a1}*pid92_7scaled + {a2}*ftdif_wb92_sc) if white_int92 == white_int94 & nmis_m2 == 0 [aweight = V940005], r
nlsur (ftdif_wb94_sc ={b0}+({b3}+{a2})*pid92_7scaled +{b2}*ftdif_wb92_sc) (pid94_7scaled ={a0}+{a1}*pid92_7scaled + {a2}*ftdif_wb92_sc) if white_int92 == white_int94 & nmis_m2 == 0 [aweight = V940005], r 

*** Table 2
* CCAP08
use "./data/ccap08_subset.dta", clear
egen nmis_m3 = rmiss2(rr_m_scaled rr_o_scaled pid7r_m_sc pid7r_o_sc)
nlsur (rr_o_scaled ={b0}+{b1}*pid7r_m_sc +{b2}*rr_m_scaled) (pid7r_o_sc ={a0}+{a1}*pid7r_m_sc + {a2}*rr_m_scaled) if nmis_m3 == 0 [aweight = weight], r
nlsur (rr_o_scaled ={b0}+({b3}+{a2})*pid7r_m_sc +{b2}*rr_m_scaled) (pid7r_o_sc ={a0}+{a1}*pid7r_m_sc + {a2}*rr_m_scaled) if nmis_m3 == 0 [aweight = weight], r

* CCAP12: March
use "./data/ccap12_subset.dta", clear
keep if p2 == 1
egen nmis_m4 = rmiss2(rr_p1_scaled rr_p2_scaled pp_pid7r_sc pid7_sc)
nlsur (rr_p2_scaled ={b0}+{b1}*pp_pid7r_sc +{b2}*rr_p1_scaled) (pid7_sc ={a0}+{a1}*pp_pid7r_sc + {a2}*rr_p1_scaled) if nmis_m4 == 0 [aweight = weight], r
nlsur (rr_p2_scaled ={b0}+({b3}+{a2})*pp_pid7r_sc +{b2}*rr_p1_scaled) (pid7_sc ={a0}+{a1}*pp_pid7r_sc + {a2}*rr_p1_scaled) if nmis_m4 == 0 [aweight = weight], r

* CCAP12: August
use "./data/ccap12_subset.dta", clear
keep if p3 == 1
egen nmis_m5 = rmiss2(rr_p1_scaled rr_p3_scaled pp_pid7r_sc pid7_sc)
nlsur (rr_p3_scaled ={b0}+{b1}*pp_pid7r_sc +{b2}*rr_p1_scaled) (pid7_sc ={a0}+{a1}*pp_pid7r_sc + {a2}*rr_p1_scaled) if nmis_m5 == 0 [aweight = weight], r
nlsur (rr_p3_scaled ={b0}+({b3}+{a2})*pp_pid7r_sc +{b2}*rr_p1_scaled) (pid7_sc ={a0}+{a1}*pp_pid7r_sc + {a2}*rr_p1_scaled) if nmis_m5 == 0 [aweight = weight], r

*** Table 3
use "./data/vsg_subset.dta", clear
egen nmis_m6 = rmiss2(rr_sc_12 rr_sc_16 pid7_sc_12 pid7_sc_16)
nlsur (rr_sc_16 ={b0}+{b1}*pid7_sc_12 +{b2}*rr_sc_12) (pid7_sc_16 ={a0}+{a1}*pid7_sc_12 + {a2}*rr_sc_12) if nmis_m6 == 0 [aweight = weight], r
nlsur (rr_sc_16 ={b0}+({b3}+{a2})*pid7_sc_12 +{b2}*rr_sc_12) (pid7_sc_16 ={a0}+{a1}*pid7_sc_12 + {a2}*rr_sc_12) if nmis_m6 == 0 [aweight = weight], r

egen nmis_m7 = rmiss2(nwa_sc_12 nwa_sc_16 pid7_sc_12 pid7_sc_16)
nlsur (nwa_sc_16 ={b0}+{b1}*pid7_sc_12 +{b2}*nwa_sc_12) (pid7_sc_16 ={a0}+{a1}*pid7_sc_12 + {a2}*nwa_sc_12) if nmis_m7 == 0 [aweight = weight], r
nlsur (nwa_sc_16 ={b0}+({b3}+{a2})*pid7_sc_12 +{b2}*nwa_sc_12) (pid7_sc_16 ={a0}+{a1}*pid7_sc_12 + {a2}*nwa_sc_12) if nmis_m7 == 0 [aweight = weight], r


*** Table 4
use "./data/ccap16_subset.dta", clear
egen nmis_m8 = rmiss2(b_rr_sc p_rr_sc b_pid7_sc p_pid7_sc)
nlsur (p_rr_sc ={b0}+{b1}*b_pid7_sc +{b2}*b_rr_sc) (p_pid7_sc ={a0}+{a1}*b_pid7_sc + {a2}*b_rr_sc) if nmis_m8 == 0 [aweight = weight_post], r 
nlsur (p_rr_sc ={b0}+({b3}+{a2})*b_pid7_sc +{b2}*b_rr_sc) (p_pid7_sc ={a0}+{a1}*b_pid7_sc + {a2}*b_rr_sc) if nmis_m9 == 0 [aweight = weight_post], r

egen nmis_m9 = rmiss2(b_wb_fav_dif p_wb_fav_dif b_pid7_sc p_pid7_sc)
nlsur (p_wb_fav_dif ={b0}+{b1}*b_pid7_sc +{b2}*b_wb_fav_dif) (p_pid7_sc ={a0}+{a1}*b_pid7_sc + {a2}*b_wb_fav_dif) if nmis_m9 == 0 [aweight = weight_post], r 
nlsur (p_wb_fav_dif ={b0}+({b3}+{a2})*b_pid7_sc +{b2}*b_wb_fav_dif) (p_pid7_sc ={a0}+{a1}*b_pid7_sc + {a2}*b_wb_fav_dif) if nmis_m9 == 0 [aweight = weight_post], r
